/**
 * 修改系统参数的窗口
 * @author linzongxue
 * @create_date 2012-2-14
 */
define(function(){
	var SysParamWindow = Ext.extend(Ext.Window, {
		paramData: null, //参数定义和值，在创建窗口时传入
		title: '修改系统参数值',
	    width: 320,
	    modal: true,
	    resizable: false,
	    bodyStyle:'padding:5px;',
	    buttonAlign:'right',
	    iconCls: 'icon-window',
	    animateTarget: cu.getDefaultAnimateTarget(),
		initComponent: function(){
			SysParamWindow.superclass.initComponent.call(Ext.apply(this, {
				items:[
				    this.formPanel = this.createForm(this.paramData)
				],
			    buttons: [
			    	{text: '保存', handler: this.save, iconCls: 'icon-save', scope: this},
			    	{text: '取消', handler: this.close, iconCls: 'icon-close', scope: this}
			    ],
				listeners: {
			    	show: function(){
			    		this.firstFocus();
						cu.bindEnter(this, this.save);
			    	}
			    }
			}));
		},
		save: function(){
			cu.submit({
				form: this.getForm(), 
				url: 'sys/param/updateSysParam.do',
				success: function(){
					var newValue = this.getForm().findField('value').getValue();
					this.close();
			    	if (this.callback){
			    		this.callback.call(this.cbScope, newValue);
			    	}
				}, 
				scope: this
			});
		},
		firstFocus: function(){
			this.getForm().findField('value').focus(true, 200);
		},
		getForm: function(){
			return this.formPanel.getForm();
		},
		createForm: function(data){
			var formPanel = new Ext.form.FormPanel({
			    baseCls: 'x-plain',
			    labelWidth: 60,
			    labelPad: 5,
			    labelAlign: "right",
			    defaults: {anchor:'99%', style:'margin: 0 0 5 5'},
			    items: [{
			    	xtype: 'hidden', name: 'name'
			    },{
			    	xtype: 'displayfield',
			        fieldLabel:'参数名',
			        name: 'displayName'
			    }, lu.isEmpty(data.values) ? {
			    	xtype: 'textfield',
			        fieldLabel: '参数值',
			        name: 'value',
			        maxLength: 255,
			        allowBlank: false
			    }:{
			    	xtype: 'combo',
			        fieldLabel: '参数值',
			        name: 'value',
					mode: 'local',
					triggerAction: 'all',
					store: data.values,
					editable: false
			    },{
			    	xtype: 'displayfield',
			    	fieldLabel: '描述',
			    	name: 'text'
			    }]
			});
			formPanel.getForm().setValues(data);
			formPanel.getForm().findField('displayName').setValue(data.name);
			return formPanel;
		}
	});
	return SysParamWindow;
});